package com.dameng.jianyouquan.jobhunter.fragment.home;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.andview.refreshview.XRefreshView;
import com.dameng.jianyouquan.R;
import com.dameng.jianyouquan.adapter.LongPeriodAdapter;

public class LongPeriodFragment extends Fragment {


    private RecyclerView recyclerView;
    private XRefreshView mXRefreshView;
    private int count=10;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = View.inflate(getContext(), R.layout.fragment_home_long_peroid, null);
        recyclerView = view.findViewById(R.id.recycler_view);
        mXRefreshView = view.findViewById(R.id.xRefreshView);
        mXRefreshView.setPullLoadEnable(true);
        mXRefreshView.setPullRefreshEnable(true);
        LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
        recyclerView.setLayoutManager(layoutManager);
        LongPeriodAdapter adapter = new LongPeriodAdapter(getLayoutInflater());
        recyclerView.setAdapter(adapter);

        mXRefreshView.setXRefreshViewListener(new XRefreshView.SimpleXRefreshListener(){
            @Override
            public void onRefresh(boolean isPullDown) {
                super.onRefresh(isPullDown);
                mXRefreshView.stopRefresh();
                count=10;
                adapter.setCount(count);

            }

            @Override
            public void onLoadMore(boolean isSilence) {
                super.onLoadMore(isSilence);
                mXRefreshView.stopLoadMore();
                adapter.setCount(count+=10);
            }
        });
        return view;
    }
}
